package com.aaa.config.swaggerconfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * knife4j配置
 *
 * @author 太阳偷渡青山
 * @date 2022/11/09
 */
@Configuration
@EnableSwagger2
public class Knife4jConfiguration {

    @Autowired
    private Knife4jProperties knife4j;

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        String groupName="3.X版本";
        Docket docket=new Docket(DocumentationType.OAS_30)
                .apiInfo(new ApiInfoBuilder()
                        .title("这是knife4j API ")
                        .description(knife4j.getDescription())
                        .termsOfServiceUrl(knife4j.getTermsOfServiceUrl())
                        .contact(new Contact(knife4j.getBasePackage(),knife4j.getTermsOfServiceUrl(),knife4j.getEmail()))
                        .version(knife4j.getVersion())
                        .build())
                //分组名称
                .groupName(groupName)
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage(knife4j.getBasePackage()))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}


//    @Value("${Knife4j.description}")
//    private String description;
//    @Value(("${Knife4j.termsOfServiceUrl}"))
//    private String termsOfServiceUrl;
//    @Value("${Knife4j.name}")
//    private String name;
//    @Value("${Knife4j.email}")
//    private String email;
//    @Value("${Knife4j.version}")
//    private String version;
//    @Value("${Knife4j.basePackage}")
//    private String basePackage;